//
//  MTBaseViewController.m
//  ebook
//
//  Created by 吴超飞 on 16/1/14.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "MTBaseViewController.h"
//#import <ShareSDKUI/ShareSDK+SSUI.h>
//#import <ShareSDKUI/SSUIShareActionSheetStyle.h>

@interface MTBaseViewController ()<CoreStatusProtocol>

@end

@implementation MTBaseViewController
@synthesize currentStatus;

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = NO;
    self.view.backgroundColor = MTConfigColor(@"MTBaseBgColor");
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = MTConfigColor(@"MTNavigationBar_background_Color");
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: MTConfigColor(@"MTNavigationBar_title_Color"),                                                                 NSFontAttributeName : [UIFont systemFontOfSize:18]};
    
    //    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;//滑动返回    -[UIGestureRecognizer _delegateShouldReceiveTouch:]换书阅读的闪退就是因为这个引起的？
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //添加网络监听通知
    [CoreStatus beginNotiNetwork:self];
    [self isNetConnect];
}

-(BOOL)prefersStatusBarHidden{
    return NO;
}

#pragma mark - navi back btn
- (void)createBackItem
{
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    backItem.tintColor = MTConfigColor(@"MTNavigationBar_leftItem_Color");
    self.navigationItem.leftBarButtonItem = backItem;
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma CoreStatusProtocol
- (void)coreNetworkChangeNoti:(NSNotification *)noti
{
    //    [self isNetConnect];
}

-(BOOL)isNetConnect{
    
    if([CoreStatus currentNetWorkStatus] == CoreNetWorkStatusNone){
        //        [LeafNotification showInController:self withText:@"网络断开，请检查网络设置" type:LeafNotificationTypeWarn];
        return NO;
    }
    return YES;
}

-(void)viewDidDisappear:(BOOL)animated{
    
    [super viewDidDisappear:animated];
    //    //移除网络监听通知
    //    [CoreStatus endNotiNetwork:self];
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
}
/*
- (void)sharewithview:(UIView *)shareView text:(NSString *)text dic:(NSDictionary *)dict imagesArray:(NSArray *)imageArray {
    
    __unsafe_unretained typeof(self) weakSelf = self;
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"%@\n%@", text, dict[@"url"]]
                                     images:imageArray
                                        url:[NSURL URLWithString:dict[@"url"]]
                                      title:dict[@"title"]
                                       type:SSDKContentTypeAuto];
    NSArray * arrays = @[@(SSDKPlatformTypeWechat),@(SSDKPlatformTypeQQ)];//@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformTypeQQ)
    
    SSUIShareActionSheetController *sheet =
    [ShareSDK showShareActionSheet:shareView
                             items:arrays
                       shareParams:shareParams
               onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                   if (state == SSDKResponseStateSuccess) {
                       __strong __typeof(self) strongSelf = weakSelf;
                       [ToastView showMsg:@"分享成功" inView:strongSelf.view isCenter:YES];
                       MTLog(@"SSDKResponseStateSuccess");
                   }
                   if (state == SSDKResponseStateFail || state == SSDKResponseStateCancel) {
                       MTLog(@"error:%@", error);
                   }
                   switch (platformType) {
                       case SSDKPlatformTypeQQ:
                           [[BaiduMobStat defaultStat] logEvent:kBaiduEvent_ShareToQQ eventLabel:@"QQ"];
                           break;
                       case SSDKPlatformTypeWechat:
                           [[BaiduMobStat defaultStat] logEvent:kBaiduEvent_ShareToWechat eventLabel:@"Wechat"];
                           break;
                       case SSDKPlatformTypeSinaWeibo:
                           [[BaiduMobStat defaultStat] logEvent:kBaiduEvent_ShareToSina eventLabel:@"Sina"];
                       default:
                           break;
                   }
               }];
    //添加平台示例  添加不会有编辑界面
    [sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];
}*/

//将某个时间戳转化成日期
-(NSString *)timestampSwitchDate:(NSInteger)timestamp {
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd"]; // （@"YYYY-MM-dd hh:mm:ss")
    
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    [formatter setTimeZone:timeZone];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp];
    
    MTLog(@"日期:%@",confromTimesp);
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    return confromTimespStr;
}

- (void)dealloc {
    
    //    [CoreStatus endNotiNetwork:self];
}

@end
